#!/bin/sh
# PCP QA Test No. 903
# Exercise fetch profile handling in a multithreaded environment.
#
# Copyright (c) 2019 Ken McDonell.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

_cleanup()
{
    cd $here
    rm -rf $tmp $tmp.* /tmp/mt13out.*
}

status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

# real QA test starts here
for src in "-h localhost" "-a tmparch/bigbin" -L
do
    echo | tee -a $seq_full
    echo "=== $src ===" | tee -a $seq_full
    [ "$src" = "-L" ] && echo "Note: expect errors with -L"
    rm -f /tmp/mt13out.*
    src/multithread13 -i -v $src -s 100 5 >$tmp.out 2>$tmp.err
    cat $tmp.err $tmp.out >>$seq_full
    cat $tmp.err $tmp.out
    for o in /tmp/mt13out.*
    do
	echo "--- $o ---" >>$seq_full
	cat $o >>$seq_full
	grep -E -v 'include|exclude| numpmid=1 ' <$o \
	| sed -e 's/^\[[0-4]]/[x]/' \
	| LC_COLLATE=posix sort
    done
done

# success, all done
status=0
exit
